package com.budwk.app.sqfwV2.generator.centuryCitySecurity.excel;

import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSONObject;
import com.budwk.app.sqfw.enums.DownLoadFileNameEnum;
import com.budwk.app.sqfw.models.Sqfw_formSummary_new;
import com.budwk.app.sqfwDoc.bo.SqfwExcelForSummaryBO;
import com.budwk.app.sqfwDoc.bo.SqfwExcelJudgeRes;
import com.budwk.app.sqfwDoc.codeGenerator.excelGenerate.BaseTemplateExcelGenerator;
import com.budwk.app.sqfwDoc.codeGenerator.excelGenerate.SqfwExcelCreateCommonBO;
import com.budwk.app.sqfwV2.component.DayingRoadPdfComponent;
import com.budwk.app.sqfwV2.component.centuryCity.CommCenturyCityDataHandleUtil;
import com.budwk.app.sqfwV2.dto.dto.centuryCity.SafeCheckGasDTO;
import com.budwk.app.sqfwV2.dto.dto.centuryCity.SafeCheckTaskPdfDTO;
import com.budwk.app.sqfwV2.dto.image.CenturyCityExcelImageConfigBO;
import com.budwk.app.sqfwV2.enums.CenturyCitySafeCheckGasExcelEnum;
import com.budwk.app.sqfwV2.enums.CenturyCitySafeCheckGasUseEnum;
import com.budwk.app.sqfwV2.enums.CenturyCitySafeServiceEnum;
import com.budwk.app.util.poiUtils.excelPictureConfigBO.ExcelFileCreateParamBO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.ObjectUtils;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author 东方祥云低代码1.1
 * @since 2024-02-18
 * <p>
 * 世纪城安全巡查表 safe_check_task
 * 燃气清单.xlsx
 */
@Slf4j
public class GasGenerator extends BaseTemplateExcelGenerator {

    @Override
    protected void customerPopularSheetBaseParam(Map<String, Object> excelParam, SqfwExcelCreateCommonBO excelCreateParam) {

    }

    @Override
    protected void customerPopularSheetDataParam(List<Map<String, Object>> listMap, SqfwExcelCreateCommonBO excelCreateParam) {
    }

    @Override
    protected String getTemplateName() {
        return CenturyCitySafeServiceEnum.CENTER_CITY_GAS_SAFE.getTemplatePath();
    }

    @Override
    public String getDownloadFileName() {
        String fileName = DayingRoadPdfComponent.getDictName(CenturyCitySafeServiceEnum.CENTER_CITY_GAS_SAFE.getCode(), null);
        if (StringUtils.isBlank(fileName)) {
            fileName = DownLoadFileNameEnum.CENTER_CITY_GAS_SAFE.getName();
        } else {
            fileName = fileName.split("\\.")[0];
        }
        return fileName + "_" + DateUtil.format(new Date(), "yyyyMMddHHmmss");
    }

    @Override
    protected void completeExcelFileCreateParam(ExcelFileCreateParamBO excelFileCreateParam) {

    }

    @Override
    protected void customerPopularRowDataMap(Map<String, Object> rowDataMap, SqfwExcelForSummaryBO forSummaryBO) {
        Sqfw_formSummary_new sqfwFormSummaryNew = forSummaryBO.getSqfwFormSummaryNew();
        SafeCheckTaskPdfDTO safeCheckTaskPdfDTO = JSONObject.parseObject(sqfwFormSummaryNew.getParamData(), SafeCheckTaskPdfDTO.class);
        SafeCheckGasDTO safeCheckGasDTO = safeCheckTaskPdfDTO.getSafeCheckGasDTO();
        String fireAndElectricityUsageStr = null;
        for (String code : safeCheckGasDTO.getFireAndElectricityUsage().split(",")) {
            //燃气使用情况 先判断是否在枚举里面且是要写入此表的数据，金阳后面新加的集中燃料不计入此excel
            CenturyCitySafeCheckGasUseEnum centuryCitySafeCheckGasUseEnum = CenturyCitySafeCheckGasUseEnum.getEnum(code);
            if(ObjectUtils.isNotEmpty(centuryCitySafeCheckGasUseEnum)){
                CenturyCitySafeCheckGasExcelEnum fireAndElectricityUsage = CenturyCitySafeCheckGasExcelEnum.getEnum(code);
                if (ObjectUtils.isNotEmpty(fireAndElectricityUsage)) {
                    if (StringUtils.isBlank(fireAndElectricityUsageStr)) {
                        fireAndElectricityUsageStr = fireAndElectricityUsage.getValue();
                    } else {
                        fireAndElectricityUsageStr = fireAndElectricityUsageStr + " " + fireAndElectricityUsage.getValue();
                    }
                }
            }
        }
        CenturyCitySafeCheckGasExcelEnum useGasCylinders = CenturyCitySafeCheckGasExcelEnum.getEnum(safeCheckGasDTO.getUseGasCylinders());
        CenturyCitySafeCheckGasExcelEnum gasCylinderCirculation = CenturyCitySafeCheckGasExcelEnum.getEnum(safeCheckGasDTO.getGasCylinderCirculation());
        CenturyCitySafeCheckGasExcelEnum gasCylinderSafety = CenturyCitySafeCheckGasExcelEnum.getEnum(safeCheckGasDTO.getGasCylinderSafety());
        CenturyCitySafeCheckGasExcelEnum connectingHoses = CenturyCitySafeCheckGasExcelEnum.getEnum(safeCheckGasDTO.getConnectingHoses());
        CenturyCitySafeCheckGasExcelEnum isOverstockedLPGCylinders = CenturyCitySafeCheckGasExcelEnum.getEnum(safeCheckGasDTO.getIsOverstockedLPGCylinders());
        CenturyCitySafeCheckGasExcelEnum combustibleGasAlarm = CenturyCitySafeCheckGasExcelEnum.getEnum(safeCheckGasDTO.getCombustibleGasAlarm());

        rowDataMap.put("fireAndElectricityUsage",StringUtils.isNotBlank(fireAndElectricityUsageStr) ? fireAndElectricityUsageStr : safeCheckGasDTO.getFireAndElectricityUsage());
        rowDataMap.put("useGasCylinders", ObjectUtils.isNotEmpty(useGasCylinders) ? useGasCylinders.getValue() : safeCheckGasDTO.getUseGasCylinders());
        rowDataMap.put("gasCylinderCirculation", ObjectUtils.isNotEmpty(gasCylinderCirculation) ? gasCylinderCirculation.getValue() : safeCheckGasDTO.getGasCylinderCirculation());
        rowDataMap.put("gasCylinderSafety", ObjectUtils.isNotEmpty(gasCylinderSafety) ? gasCylinderSafety.getValue() : safeCheckGasDTO.getGasCylinderSafety());
        rowDataMap.put("connectingHoses", ObjectUtils.isNotEmpty(connectingHoses) ? connectingHoses.getValue() : safeCheckGasDTO.getConnectingHoses());
        rowDataMap.put("isOverstockedLPGCylinders", ObjectUtils.isNotEmpty(isOverstockedLPGCylinders) ? isOverstockedLPGCylinders.getValue() : safeCheckGasDTO.getIsOverstockedLPGCylinders());
        rowDataMap.put("combustibleGasAlarm", ObjectUtils.isNotEmpty(combustibleGasAlarm) ? combustibleGasAlarm.getValue() : safeCheckGasDTO.getCombustibleGasAlarm());
        rowDataMap.put("otherHiddenDangers", safeCheckGasDTO.getOtherHiddenDangers());
        rowDataMap.put("crossRegionalDelivery", safeCheckGasDTO.getCrossRegionalDelivery());

        rowDataMap.put("fillDateStr", DateUtil.format(sqfwFormSummaryNew.getFillDate(), "yyyy年MM月dd日"));
        rowDataMap.put("remark", safeCheckGasDTO.getRemark());


        //CommCenturyCityDataHandleUtil.rowDataBuild(rowDataMap, forSummaryBO);
    }

    @Override
    protected SqfwExcelJudgeRes judgeDataIntoExcelBeforeErgodic(SqfwExcelCreateCommonBO excelCreateParam, Map<String, Object> excelParam) {
        return null;
    }

    @Override
    protected SqfwExcelJudgeRes judgeDataIntoExcelBeforeCreate(Map<String, Object> excelParam) {
        return null;
    }

    @Override
    protected Class<?> getImageConfigBO() {
        return CenturyCityExcelImageConfigBO.class;
    }

    public boolean isGenerateExcel(List<Sqfw_formSummary_new> dataList) {
        return CommCenturyCityDataHandleUtil.checkData(dataList);
    }

}
